<?php
class Profile_model extends CI_Model {

	/**
	 * @author Pwint Phyu Shwe
	 * Profile Model for tbl_user and tbl_userdetails tables
	 * CRUD of User Profile Realated.
	 * This model include pagination and related functions.
	 * Refer detail in each function's comment section below.
	 */
	// table name
	private $tbl_user = 'masteruser';
	private $tbl_userdetails = 'userdetails';

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
	}
	// get number of users in database
	function count_all(){
		return $this->db->count_all($this->tbl_user);
	}
	// get persons with paging
	function get_paged_list($limit = 10, $offset = 0){
		$this->db->order_by('userID','asc');
		return $this->db->get($this->tbl_user, $limit, $offset);
	}
	// get person by userID
	function get_by_id($userID){
		$this->db->where('userID', $userID);
		$query = $this->db->get($this->tbl_user);
		$results = $query->result();
		$query->free_result(); //free result
		return $results;
	}
	// add new person
	function save($user){
		$this->db->insert($this->tbl_user, $user);
		return $this->db->insert_id();
	}
	// update person by userID
	function update($cond = NULL, $user){
		if ($cond != NULL){
			foreach ($cond as  $param => $item)
				$this->db->where($param , $item);
		}
		$this->db->update($this->$tbl_user, $user);
	}
	// delete person by userID
	function delete($userID){
		$this->db->where('userID', $userID);
		$this->db->delete($this->$tbl_user);
	}
	//get advertiser contact's information
	function get_contact($userID){
		$this->db->select('firstName, emailAddress, phone');
		$this->db->where('userID', $userID);
		$query = $this->db->get($this->tbl_user);
		
		$result = $query->result_array();
		$query->free_result(); //free result
		return $result;
	}
}
?>